﻿<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>ADD_Update_Delete</Title>
    <Author>jinlei</Author>
    <Shortcut>ADD_Update_Delete</Shortcut>
    <Description>ADD_Update_Delete</Description>
    <SnippetTypes>
      <SnippetType>SurroundsWith</SnippetType>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Code Language="CSharp">
      <![CDATA[List<CameraSettingControl> add = new List<CameraSettingControl>();
            List<CameraSettingControl> update = new List<CameraSettingControl>();
            List<CameraSettingControl> delete = new List<CameraSettingControl>();
            foreach (CameraCfg cfg in Model.Cameras.Cameras)
            {
                CameraSettingControl ct = _camControls.FirstOrDefault(x => x.Camcfg.uId.Equals(cfg.uId));
                if (ct == null)
                {
                    ct = new CameraSettingControl();
                    #region Add
                    #endregion
                    add.Add(ct);
                }
                else
                {
                    update.Add(ct);
                }
            }
            foreach (CameraSettingControl ct in _camControls)
            {
                CameraCfg cfg = Model.Cameras.Cameras.FirstOrDefault(x => x.uId.Equals(ct.Camcfg.uId));
                if (cfg == null)
                    delete.Add(ct);
            }
            foreach (CameraSettingControl ct in delete)
            {
                fsDockContainer1.RemoveControl(ct);
                _camControls.Remove(ct);
                #region delete

                #endregion
                ct.Dispose();
            }
            delete.Clear(); delete = null;
            add.ForEach(x => fsDockContainer1.AddControl(string.Format("{0}-{1}", x.Camcfg.Flag.ToString(), x.Camcfg.Name), x));
            _camControls.AddRange(add);
            add.Clear(); add = null;
            update.ForEach(x => fsDockContainer1.UpdateControl(string.Format("{0}-{1}", x.Camcfg.Flag.ToString(), x.Camcfg.Name), x));
            update.Clear(); update = null;]]>
    </Code>
  </Snippet>
</CodeSnippet>